<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>$Title$</title>
</head>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/laypage.css">
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/laypage/laypage.js"></script>
<script type="text/javascript" src="/js/layer/layer.js"></script>
<script type="text/javascript" src="/js/vue/vue.min.js"></script>
<body>
<h1>欢迎您，${user.username}</h1>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="/logout">退出</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="/free/admin.do">ADMIN</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="/free/user.do">USER</a>
<div id="app" class="container">

    <form class="form-inline bg-danger" role="form">
        查询条件：
        <div class="form-group">
            <label class="sr-only" for="username">部门名称</label>
            <input type="text" class="form-control" id="username" placeholder="姓名">
        </div>
        <button type="button" id="findUser" class="btn btn-success">查询</button>
        <button type="button" id="addUserBtn" class="btn btn-danger">增加</button>
    </form>

    <div class="table-responsive">
        <table class="table">
            <thead>
            <tr class="success">
                <td>序号</td>
                <td>姓名</td>
                <td>年龄</td>
                <td>操作</td>
            </tr>
            </thead>

            <tbody>
            <tr class="active" v-for="(item,index) in result">
                <td>{{index+1}}</td>
                <td>{{item.username}}</td>
                <td>{{item.powers}}</td>
                <td><a href="#" @click = "editEvent(item.id)">编辑</a>|<a href="#" @click="delEvent(item.id)">删除</a></td>
            </tr>
            </tbody>
        </table>
        <div id="pagenav"></div>
    </div>
</div>
<input type="hidden" id="curr"/>
</body>
</html>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            result: []
        }
    });
    var getDeptPageList = function (curr) {
        $.ajax({
            type:'GET',
            dataType:'json',
            url:"/free/getPage.do",
            contentType:"application/json",
            data: {
                pageNum: curr || 1,
                pageSize:3,
                username: $("#username").val()
            },
            success:function (msg) {
                app.result = msg.result;
                $("#curr").val(msg.pageNum);

                laypage({
                    cont: 'pagenav',
                    pages: msg.totalPage,
                    skip: true,
                    skin: '#7B68EE',
                    first : '首页',
                    last : '尾页',
                    curr: curr || 1,
                    jump: function (obj, first) {
                        if (!first) {
                            getDeptPageList(obj.curr);
                        }
                    }
                });
            },
            error:function () {
                alert("error");

            }
        });
    }

        getDeptPageList();
    $("#findUser").on("click",function () {
        getDeptPageList();
    })

    /*新增*/
    $("#addUserBtn").on("click",function () {
        layer.open({
            type:2,
            title:'新增用户',
            fix:false,
            maxmin:true,
            shadeClose:true,
            area:['800px','500px'],
            content:'/addUser.html',
            end: function(){
                //更新页面信息
                getDeptPageList($("#curr").val());
            }
        })
    })
    /*删除*/
    var delEvent = function (id) {
        layer.confirm('确定要删除吗？',{
            btn:['是','否']
        },function () {
            //是
            $.ajax({
                type:'GET',
                dataType:'json',
                url:'/free/delUser.do',
                data:{
                    id:id
                },success:function (msg) {
                    getDeptPageList();
                    layer.msg('删除成功'+id,{icon:6});
                }
            });
        }, function () {
                });
    }
    /*修改*/
    var editEvent = function (id) {
        layer.open({
            type:2,
            title:'修改用户',
            fix:false,
            maxmin:true,
            shadeClose:true,
            area:['800px','500px'],
            content:'/free/findUser.do?id='+id,
            end: function(){
                //更新页面信息
                getDeptPageList($("#curr").val());
            }
        })
    }
</script>